Ext.namespace('Divo');
Ext.namespace('Divo.app');

Divo.app.ReadyCodeForm = Ext.extend(Divo.Base.EditForm, {
  fields : new Ext.util.MixedCollection(),
  dataRecordMeta : Ext.data.Record.create([{
        name : "_p_record_status",
        type : "string"
      }, {
        name : "id",
        type : "float"
      }, {
        name : "materialId",
        type : "float"
      }, {
        name : "supplierId",
        type : "float"
      }, {
        name : "endTime",
        type : "string"
      }, {
        name : "cancelCodeTime",
        type : "string"
      }, {
        name : "cancelCodeWho",
        type : "string"
      }, {
        name : "materialName",
        type : "string"
      }, {
        name : "name",
        type : "string"
      }]),
  initComponent : function() {
    var me = this;
    var tn = 1;

    this.fields.add("_p_record_status", new Ext.form.Hidden({
              name : "_p_record_status"
            }));
    this.fields.add("id", new Ext.form.Hidden({
              name : "id",
              dataIndex : "id",
              insert_allowed : true,
              update_allowed : true
            }));
    this.fields.add("materialName", new Ext.form.Hidden({
              name : "materialName",
              dataIndex : "materialName",
              insert_allowed : true,
              update_allowed : true
            }));
    this.fields.add("name", new Ext.form.Hidden({
              name : "name",
              dataIndex : "name",
              insert_allowed : true,
              update_allowed : true
            }));
    this.fields.add("supplierId", new Ext.form.Hidden({
              name : "supplierId",
              dataIndex : "supplierId",
              insert_allowed : true,
              update_allowed : true
            }));
    this.fields.add("materialId", new Ext.form.Hidden({
              name : "materialId",
              dataIndex : "materialId",
              insert_allowed : true,
              update_allowed : true
            }));
    this.fields.add("endTime", new app.base.DateField({
              name : "endTime",
              dataIndex : "endTime",
              format : 'Y.m.d',
              fieldLabel : "有效日期",
              allowBlank : false,
              labelSeparator : ":*",
              tabIndex : tn++,
              width : 150,
              editable : true,
              insert_allowed : true,
              update_allowed : true
            }));
    this.fields.add("supplier", new app.base.ComboBox({
              fieldLabel : '选择供应商',
              name : 'supplier',
              tabIndex : tn++,
              store : Divo.com.Lib.getSupplierEnableDs(),
              displayField : 'name',
              dataIndex : 'supplier',
              mode : 'remote',
              typeAhead : false,
              forceSelection : true,
              loadingText : '正在搜索...',
              listWidth : 300,
              labelSeparator : ":*",
              width : 150,
              minChars : 0,
              allowBlank : false,
              tpl : Divo.com.Lib.getEnterpriseTpl(),
              insert_allowed : true,
              update_allowed : true,
              onSelect : function(record) {
                var data = record.data;
                me.setFieldValue("supplier", data.name);
                me.setFieldValue("supplierId", data.id);
                this.onTriggerClick();
              }
            }));
    var DeptsDataWin;
    var queryDepart = function() {
      if (!DeptsDataWin) {
        DeptsDataWin = new Divo.app.CompanySelGridWin();
        DeptsDataWin.on('exportSelectItem', function(id, mName, name) {
          me.getForm().findField("materialId").setValue(id);
          me.getForm().findField("materialNameG").setValue(name + "--" + mName);
          me.getForm().findField("materialName").setValue(mName);
          me.getForm().findField("name").setValue(name);
        }, this);
      }
      DeptsDataWin.showDialog();
    };

    this.fields.add("materialNameG", new app.base.TextField({
              fieldLabel : '选择高值耗材',
              name : "materialNameG",
              dataIndex : "materialNameG",
              allowBlank : false,
              labelSeparator : ":*",
              tabIndex : tn++,
              width : 130,
              insert_allowed : true,
              update_allowed : true
            }));

    Ext.apply(this, {
          items : [this.fields.get("_p_record_status"), {
            layout : "form",
            columnWidth : 1,
            labelAlign : "right",
            labelWidth : 100,
            items : [this.fields.get("id"), this.fields.get("supplierId"),
                this.fields.get("materialId"), this.fields.get("materialName"),
                this.fields.get("name"), {
                  layout : "column",
                  bodyStyle : 'padding:0 0 ;',
                  border : false,
                  width : 270,
                  items : [{
                        layout : "form",
                        columnWidth : .9,
                        labelAlign : "right",
                        border : false,
                        width : 230,
                        items : [this.fields.get("materialNameG")]
                      }, {
                        layout : "form",
                        columnWidth : .1,
                        border : false,
                        items : [new Ext.Button({
                              id : "btn_queryDepart",
                              icon : 'resources/img/fam.icons/search.gif',
                              handler : function() {
                                queryDepart();
                              }
                            })]
                      }]
                }, this.fields.get("supplier"), this.fields.get("endTime")]
          }],
          border : false,
          frame : true,
          firstFocusFieldName : "materialNameG"
        });

    Divo.app.ReadyCodeForm.superclass.initComponent.apply(this, arguments);
  }

  ,
  onRender : function() {
    Divo.app.ReadyCodeForm.superclass.onRender.apply(this, arguments);
  },
  newDataRecord : function() {
    return new this.dataRecordMeta({
          _p_record_status : "insert",
          id : "",
          name : "",
          state : ""
        });
  }

});
Ext.reg("Divo.app.ReadyCodeForm", Divo.app.ReadyCodeForm);